using System.Collections.Generic;
using System.Runtime.Serialization;
using System.Text;

namespace Aluetjen.EmailService.Domain.Models.Message
{
    [KnownType(typeof(UTF8Encoding))]
    [KnownType(typeof(DecoderReplacementFallback))]
    [KnownType(typeof(EncoderReplacementFallback))]
    public class MailMessage : Entity
    {
        public virtual int Id { get; set; }

        public virtual MailAddress Sender { get; set; }
        public virtual MailAddress From { get; set; }
        public virtual List<MailAddress> ReplyToList { get; set; }
        public virtual List<MailAddress> To { get; set; }
        public virtual List<MailAddress> Bcc { get; set; }
        public virtual List<MailAddress> CC { get; set; }
        public virtual string Subject { get; set; }
        public virtual string Body { get; set; }
        public virtual MailPriority Priority { get; set; }

        public virtual Encoding SubjectEncoding { get; set; }
        public virtual Encoding BodyEncoding { get; set; }
        public virtual Encoding HeadersEncoding { get; set; }

        public virtual bool IsBodyHtml { get; set; }

        public virtual DeliveryNotificationOptions DeliveryNotificationOptions { get; set; }

        public virtual List<Attachment> Attachments { get; set; }

        public MailMessage()
        {
        }

        public MailMessage(string from, string to, string subject, string body, bool isBodyHtml = false, Encoding bodyEncoding = null)
        {
            To = new List<MailAddress> {new MailAddress {Address = to}};
            From = new MailAddress {Address = from};
            Subject = subject;
            Body = body;
            BodyEncoding = bodyEncoding ?? Encoding.UTF8;
            IsBodyHtml = isBodyHtml;
        }
    }
}